//
//  MJRefreshFooter.swift
//  OC-Swift
//
//  Created by 陆文宇 on 2017/2/15.
//  Copyright © 2017年 陆文宇. All rights reserved.
//

import UIKit

class MJRefreshFooter: MJRefreshComponent {
    
    var automaticallyHidden: Bool = false
    init(refreshingClosure: @escaping MJRefreshComponentRefreshingClosure) {
        super.init(frame: .zero)
        
        self.refreshingClosure = refreshingClosure
    }
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    

    override func prepare() {
        super.prepare()
        
        mj_h = MJRefreshFooterHeight
    }
    
    override func willMove(toSuperview newSuperview: UIView?) {
        super.willMove(toSuperview: newSuperview)
        
        if newSuperview != nil {
            if scrollView is UITableView || scrollView is UICollectionView {
                scrollView?.mj_reloadDataClosure = { [unowned self] (totalDataCount) in
                    if self.automaticallyHidden {
                        self.isHidden = totalDataCount == 0
                    }
                }
            }
        }
    }
    
    func endRefreshingWithNoMoreData() -> Void {
        state = .noMoreData
    }
    
    func noticeNoMoreData() -> Void {
        endRefreshingWithNoMoreData()
    }
    
    func resetNoMoreData() -> Void {
        state = .idle
    }


    /*
    // Only override draw() if you perform custom drawing.
    // An empty implementation adversely affects performance during animation.
    override func draw(_ rect: CGRect) {
        // Drawing code
    }
    */

}
